package org.ucas.faker.web.utils.model;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class Heatmap {

    public Heatmap(){
        List<String> yList = new ArrayList<String>();
        yList.add("0%");
        yList.add("10%");
        yList.add("20%");
        yList.add("30%");
        yList.add("40%");
        yList.add("50%");
        yList.add("60%");
        yList.add("70%");
        yList.add("80%");
        yList.add("90%");
        yList.add("100%");
        setYLabel(yList);
      }

    private HashMap<String, List<String>> result = new HashMap<String, List<String>>();
    private List<List<String>> patentsFromWord = new ArrayList<List<String>>();
    private List<List<String>> patentsFromSeries = new ArrayList<List<String>>();


    public HashMap<String, List<String>> getResult() {
        return this.result;
    }

    public void setXLabel(List<String> list){
        this.result.put("xlabel", list);
    }

    public void setYLabel(List<String> list){
        this.result.put("ylabel", list);
    }

    public void setLine(List<String> list, int n){
        this.result.put("value"+n, list);
    }

    public void setGraphLable(List<String> list) {this.result.put("graphLable", list);}

    public List<List<String>> getPatentsFromWord() {
        return patentsFromWord;
    }

    public void setPatentsFromWord(List<List<String>> patentsFromWord) {
        this.patentsFromWord = patentsFromWord;
    }

    public List<List<String>> getPatentsFromSeries() {
        return patentsFromSeries;
    }

    public void setPatentsFromSeries(List<List<String>> patentsFromSeries) {
        this.patentsFromSeries = patentsFromSeries;
    }

    public void addWord(String word, double x, double y, List<String> patentList){
        DecimalFormat df = new DecimalFormat("0.00");

        if (!result.containsKey("hotlabel")){
            List<String> wordList = new ArrayList<String>();
            wordList.add(word);
            result.put("hotlabel", wordList);

            List<String> xList = new ArrayList<String>();
            xList.add(df.format(x));
            result.put("xaxis", xList);

            List<String> yList = new ArrayList<String>();
            yList.add(df.format(y));
            result.put("yaxis", yList);
        } else {
            List<String> wordList = result.get("hotlabel");
            wordList.add(word);
            result.put("hotlabel", wordList);

            List<String> xList = result.get("xaxis");
            xList.add(df.format(x));
            result.put("xaxis", xList);

            List<String> yList = result.get("yaxis");
            yList.add(df.format(y));
            result.put("yaxis", yList);
        }
        patentsFromWord.add(patentList);
    }

    public double getXMax(){
        return result.get("xlabel").size()-1.0;
    }

    public double[] convertWordCoordinate(double x, double y){
        double x_max = result.get("xlabel").size()-1.0;
        double x_min = 0.0;
        double y_max = 1.0;
        double y_min = 0.0;

        double xN_max = 0.95;
        double xN_min = 0.05;
        double yN_max = 0.95;
        double yN_min = 0.10;

        double x_new = (x-x_min)/(x_max-x_min)*(xN_max-xN_min)+xN_min;
        double y_new = (y_max-y)/(y_max-y_min)*(yN_max-yN_min)+yN_min;

        double coo[] = new double[2];
        coo[0] = x_new;
        coo[1] = y_new;
        return coo;
    }

/*    public void convertList(){
        if (!result.containsKey("hotlabel")){
            for (int i=0;i<result.get("hotlabel").size();i++){
                double cooX = Double.parseDouble(result.get("xaxis").get(i));
            }
        }
    }*/

    public void printResult(){
        for (String key : result.keySet()){
            System.out.println("key: "+key);
            for (String tmp : result.get(key)){
                System.out.print(tmp+"   ");
            }
            System.out.println();
        }

        if (result.containsKey("hotlabel")){
            for (int i=0;i<result.get("hotlabel").size();i++){
//            	注释system。out
                System.out.println(result.get("hotlabel").get(i)+" ("+result.get("xaxis").get(i)+", "+result.get("yaxis").get(i)+")");
            }
        }
    }

/*    public void checkWord(){
        List<String> wordList = result.get("hotlabel");
        if (wordList == null){
            return;
        }

        List<String> xList = result.get("xaxis");
        List<String> yList = result.get("yaxis");

        List<String> resultWordList = new ArrayList<String>();
        List<String> resultXWordList = new ArrayList<String>();
        List<String> resultYWordList = new ArrayList<String>();

        for (int i=0;i<wordList.size();i++){
            double x =
        }

        result.put("hotlabel", wordList);
        result.put("xaxis", xList);
        result.put("yaxis", yList);
    }*/
}
